package com.yigang.controller;

import java.text.ParseException;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yigang.entity.OrderAndProduct;
import com.yigang.entity.Theorder;
import com.yigang.service.TheorderService;
import com.yigang.utils.ResultUtil;
/**
 * @author 陈佳祥
 *订单管理
 */
@Controller
@RequestMapping("/theorder")
public class TheorderController {
	
	@Autowired
	private TheorderService theorderService;
	//妞ょ敻娼伴柌宥呯暰閸氾拷
	@RequestMapping("theorderList")
	public String theorderList() {
		return "jsp/theorder/theorderList";
	}
	@RequestMapping("addtheorder")
	public String addTheorder() {
		return "jsp/theorder/addTheorder";
	}
	
	@RequestMapping("editTheorder/{id}")
	public String editTheorder(@PathVariable("id") int id, HttpSession session) {
		Theorder theorder = theorderService.selectTheorderById(id);
	
		session.setAttribute("theorder", theorder);
		return "jsp/theorder/editTheorder";
	}
	
	@RequestMapping("theorderDetails")
	public String theorderDetails(OrderAndProduct orderAndProduct, HttpSession session) {
		OrderAndProduct orderDetails = theorderService.selectOrderAndProduct(orderAndProduct);
	
		session.setAttribute("getTheorderId", orderDetails);
		return "jsp/theorder/theorderDetails";
	}
	
	@RequestMapping("getTheorderDetails")
	@ResponseBody
	public ResultUtil getTheorderDetails(Integer page, Integer limit, OrderAndProduct orderAndProduct) {

	
		
		return theorderService.getTheorderDetails(page, limit, orderAndProduct);
	}
	
	//婢х偛鍨归弻銉︽暭閺傝纭�
	@RequestMapping("insertTheorder")
	@ResponseBody
	public ResultUtil insertTheorder(Theorder record) {
		theorderService.insertSelective(record);
		return ResultUtil.ok();

	}

	@RequestMapping("deleteTheorderById")
	@ResponseBody
	public ResultUtil deleteTheorderById(int theorderId) {
		
		return theorderService.deleteByPrimaryKey(theorderId);
	}

	@RequestMapping("getTheorderList")
	@ResponseBody
	public ResultUtil getTheorderList(Integer page, Integer limit, Theorder record) {

		return theorderService.selectTheorderList(page, limit, record);
	}

	@RequestMapping("updateTheorder")
	@ResponseBody
	public ResultUtil updateTheorder(Theorder record) throws ParseException {
		
		return theorderService.updateByPrimaryKeySelective(record);
	}
	
	
}
